// 同步钩子 -- 参数传递
class SyncWaterfallHook {
  // args => ['name']
  constructor(args) {
    this.tasks = [];
  }
  tap(name, task) {
    this.tasks.push(task);
  }
  call(...args) {
    let [first, ...others] = this.tasks;
    let ret = first(...args);
    others.reduce((pre, cur) => {
      return cur(pre) || pre;;
    }, ret);
  }
}

let hook = new SyncWaterfallHook(["name"]);

hook.tap("node", function (name) {
  console.log("前端小溪(" + name + ") --- 学习node");
  return "我不想学了";
});
hook.tap("react", function (name) {
  console.log("前端小溪(" + name + ") --- 学习react");
});
hook.tap("webpack", function (name) {
  console.log("前端小溪(" + name + ") --- 学习webpack");
});
hook.tap("vue", function (name) {
  console.log("前端小溪(" + name + ") --- 学习vue");
});

hook.call("xiaoxi");
